<?php
/**
 * Subcategoryadmin_Data_Updatesubcategory
 * update subcategory 
 * @author Adrian Stolarski
 */
class Subcategoryadmin_Data_Updatesubcategory implements Subcategoryadmin_Data_Mainable, 
        Subcategoryadmin_Data_Preparable, Subcategoryadmin_Data_Redirectable {
    
    /**
     *
     * @var type $database
     * database handler
     */
    public $database;
    /**
     *
     * @var type $database_query 
     * database query handler
     */
    public $database_query;
    /**
     *
     * @var type $redirect_action
     * redirect action handler
     */
    public $redirect_action;
    
    /**
     * constructor()
     */
    public function __construct() {
        $this->database = new Core_Driver_MysqlImproved;
    }
    
    /**
     * main()
     * udpate sub category data
     * 
     * @param array $variables
     */
    public function main(array $variables = null) {
        $this->database->connect();
        foreach($variables as $key => $value){
            $variables[$key] = $this->database->escape($value);
        }
        $this->prepare_query($variables);
        //echo $this->database_query;
        //die();
        $this->database->prepare($this->database_query);
        $this->database->query();
        $this->database->dataOperations();
        $this->redirect_action($variables);
    }
    
    /**
     * prepare_query()
     * preapre update sub category id
     * @param array $variables
     */
    public function prepare_query(array $variables = null) {
        $this->database_query = "UPDATE "
                . "page_sub_category"
                . " SET "
                . "sub_category_name='"
                .$variables['sub_category_name'].
                "', "
                . "sub_category_title='"
                .$variables['sub_category_title'].
                "', "
                . "sub_category_keywords='"
                .$variables['sub_category_keywords'].
                "', "
                . "sub_category_description='"
                .$variables['sub_category_description'].
                "', "
                . "sub_category_access_level='"
                .$variables['sub_category_access_level'].
                "', "
                . "sub_category_main_category_id='"
                .$variables['sub_category_main_category_id'].
                "'"
                . " WHERE "
                . "id="
                .$variables['sub_category_id'].
                ";";
    }

    /**
     * 
     * @param array $variables
     */
    public function redirect_action(array $variables = null) {
        $this->redirect_action = new Subcategoryadmin_Data_Subcategoryredirect;
        $this->redirect_action->main($variables);
    }

}
